//
//  BZVisitorTableVC.swift
//  weibo
//
//  Created by zzx on 2017/7/23.
//  Copyright © 2017年 zzx. All rights reserved.
//

import UIKit

class BZVisitorTableVC: UITableViewController {

    var isLogin: Bool = BZUserAccountViewModel.sharedViewModel.isLogin
    
    //设置访问视图
    var visitorView: BZVisitorView?
    
    //MARK:- 加载视图
    override func loadView() {
        
        if isLogin {
            
            super.loadView()
            
        }else{
            
            visitorView = BZVisitorView()
            
            visitorView?.delegate = self
            
            visitorView?.loginCallBack = {
            
                print("这是闭包回调")
                self.entherLogin()
            
            }
            
            
            view = visitorView
            
            setupNavigationItem()
            
        }
    }
    
    //MARK:- 已完成的视图加载
    override func viewDidLoad() {
        super.viewDidLoad()
        
        
        
    }
    
    
 
    
    //MARK:- 设置导航栏按钮
    private func setupNavigationItem() {
        
        navigationItem.leftBarButtonItem = UIBarButtonItem(title: "注册", target: self, action: #selector(registerAction))
        
        navigationItem.rightBarButtonItem = UIBarButtonItem(title: "登陆", target: self, action: #selector(loginAction))
        
    }
    
    //注册的按钮
    @objc fileprivate func registerAction() {
        
        entherLogin()
        
        
        
    }
    
    //MARK:- 跳转到登陆界面的方法
    private func entherLogin() {
        
        let oauthView = BZOAuthViewController()
        
        let nav = BZNavigationController(rootViewController: oauthView)
        
        self.present(nav, animated: true, completion: nil)
        
    }
    
    @objc fileprivate func loginAction() {
        
        entherLogin()
        print("登陆")
        
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }


}

extension BZVisitorTableVC: BZVisitorViewDelegate {

    func loginOperation() {
        print("这是代理回调")
    }

}
